﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Data;

namespace ProgrammersCalculator.Convertor
{
#if !SILVERLIGHT
    [ValueConversion(typeof(string), typeof(bool), ParameterType = typeof(string))]
#endif
    public class IsMatchConverter : IMultiValueConverter
    {
        

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((values[0] == null) || (values[1] == null))
            {
                return false;
            }

            Regex regex = new Regex((string)values[1],RegexOptions.Multiline|RegexOptions.IgnoreCase);
            var inputText = (string)values[0];
            
            Match match = regex.Match(inputText);
            if (regex.IsMatch((string)values[0]))
            {
                return match.Value;
            }
            return null;
            
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
